package com.bailiban.aigou.admin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bailiban.aigou.admin.dao.ProductDao;
import com.bailiban.aigou.admin.entity.Product;
import com.bailiban.aigou.admin.service.IProductService;
import com.bailiban.aigou.admin.utils.PageModel;
@Service
public class ProductServiceImpl implements IProductService {
	@Autowired 
	private ProductDao productDao = null;
	
	@Transactional
	public PageModel<Product> getProductPages(int pageNo, int pageSize) {
		PageModel<Product> productPages = productDao.getProductPages(pageNo, pageSize);
		
		productPages.setTotalRecords(productDao.getProductCount());
		return productPages;
		
	}

	@Transactional
	public void addProduct(Product product) {
		productDao.addProduct(product);

	}

	@Transactional
	public Product getProductById(String id) {
	
		return productDao.getProductById(id);
	}

	@Transactional
	public void updateProduct(Product product) {
		
		productDao.updateProduct(product);
	}

	@Transactional
	public void deleteProductById(String id) {
	
		productDao.deleteProductById(id);
	}

	@Transactional
	public List<Product> getAllProducts() {
		
		return productDao.getAllProducts();
	}
	/**
	 * 获取最新产品
	 * @param num 返回的条数
	 * @return
	 * @
	 */
	@Transactional
	public List<Product> getNewProducts(int num) {
	
		return productDao.getNewProducts(num);
	}
	/**
	 * 根据参数返回指定结果集
	 * @param product
	 * @param num
	 * @return
	 * @
	 */
	@Transactional
	public List<Product> getProductsByType(Product product, int num) {
		
		return productDao.getProductsByType(product, num);
	}
	/**
	 * 获取商品销量排行榜
	 * @return
	 * @
	 */
	@Transactional
	public List<Product> getProductRankings() {
	
		return productDao.getProductRankings();
	}

}
